package com.lxw.study.behavioral.command.case3;

public class Client {
    public static void main(String[] args) {
        // Initialize the text editor and invoker
        StringBuilder textEditor = new StringBuilder();
        CommandInvoker invoker = new CommandInvoker();

        // Insert "Hello, "
        invoker.execute(new InsertTextCommand("Hello, ", textEditor, 0));
        System.out.println("Insert Hello, :" + textEditor.toString());
        // Insert "world!"
        invoker.execute(new InsertTextCommand("world!", textEditor, 7));
        System.out.println("Insert world!:" + textEditor.toString());
        // Delete ", "
        invoker.execute(new DeleteTextCommand(textEditor, 5, 2));
        System.out.println("Delete , :" + textEditor.toString());
        invoker.undo(); // Undo delete - should be back to "Hello, world!"
        System.out.println("After undo: " + textEditor.toString());

        invoker.undo(); // Undo last insert - should be back to "Hello, "
        System.out.println("After undo: " + textEditor.toString());

        invoker.redo(); // Redo last insert - should be back to "Hello, world!"
        System.out.println("After redo: " + textEditor.toString());
    }
}
